package exam.test;

import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.Set;

public class MergeNames {
    public static String[] uniqueNames(String[] names1, String[] names2) {
        if (names1 == null) {
            return names2;
        }
        if (names2 == null) {
            return names1;
        }
        Set<String> set = new LinkedHashSet<>(Arrays.asList(names1));
        set.addAll(Arrays.asList(names2));
        return set.toArray(new String[0]);
    }

    public static void main(String[] args) {
        String[] names1 = new String[]{"Ava", "Emma", "Olivia"};
        String[] names2 = new String[]{"Olivia", "Sophia", "Emma"};
        System.out.println(String.join(", ", MergeNames.uniqueNames(names1, names2)));
    }
}
